package com.atguigu.tingshu.order.reciever;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
@Component
public class DelayMsgConSumer {
    @Autowired
    RedissonClient redissonClient;
    @Autowired
    OrderInfoService orderInfoService;
    @PostConstruct
    public void OrderCancal() {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        // 1.获取订单信息
        executorService.submit(() -> {
            while (true) {
                String orderNo = "";
                RBlockingQueue<Object> blockingQueue = redissonClient.getBlockingQueue(KafkaConstant.QUEUE_ORDER_CANCEL);
                try {
                    orderNo = (String) blockingQueue.take();
                    log.info("订单取消成功", orderNo);
                    orderInfoService.orderCancal(orderNo);

                } catch (InterruptedException e) {
                    log.error("订单取消失败", orderNo);
                }
            }
        });


        // 2.判断订单是否超时
    }
}
